<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学期" prop="term">
        <!-- <el-input v-model="queryParams.term" placeholder="请输入学期" clearable @keyup.enter.native="handleQuery" /> -->
        <el-select v-model="queryParams.term" placeholder="请选择学期">
          <el-option v-for="option in schoolYears" :key="option.schoolYearId" :label="option.schoolYearId"
            :value="option.schoolYearId" />
        </el-select>
      </el-form-item>
      <el-form-item label="学生学号" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入学生学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择审核状态" style="width: 100%">
          <el-option v-for="dict in dict.type.labour_score_state" :key="dict.value" :label="dict.label"
            :value="parseInt(dict.value)"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="子项目内容" prop="projectSonDetail">
        <el-input
          v-model="queryParams.projectSonDetail"
          placeholder="请输入子项目内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时长" prop="timeLong">
        <el-date-picker clearable
          v-model="queryParams.timeLong"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择时长">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="等级" prop="grade">
        <el-input
          v-model="queryParams.grade"
          placeholder="请输入等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本次获取的积分" prop="nowScore">
        <el-input
          v-model="queryParams.nowScore"
          placeholder="请输入本次获取的积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="劳动教育累计积分" prop="allScore">
        <el-input
          v-model="queryParams.allScore"
          placeholder="请输入劳动教育累计积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核部门" prop="gradeDepartment">
        <el-input
          v-model="queryParams.gradeDepartment"
          placeholder="请输入审核部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['educationManager:score:add']">劳动教育积分申报</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['educationManager:score:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['educationManager:score:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['educationManager:score:export']"
        >导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['educationManager:score:Import']">智能数据分析</el-button>
        <!-- @click="handleExport" -->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scoreList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="(劳动积分表)" align="center" prop="scoreId" /> -->
      <el-table-column label="学期" align="center" prop="term" width="100" />
      <el-table-column label="学生" align="center" prop="userName" >
        <template slot-scope="scope">
          <span>{{ scope.row.studentName }}</span><br/>
          <span>{{ scope.row.userName }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="学生姓名" align="center" prop="studentName" /> -->
      <el-table-column label="班级" align="center" prop="classNo" />
      <el-table-column label="项目类型" align="center" prop="projectType" />
      <el-table-column label="子项目内容" align="center" prop="projectSonDetail" width="160" >
        <template slot-scope="scope">
          <div>{{ scope.row.projectSonDetail  }}</div>
          <div
            style="border-top: 1px solid #ddd"
            v-for="(val, index) in scope.row.childrenScore"
            :key="index"
          >
            <div>{{ '\n'+ val.projectSonDetail  }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="时长" align="center" prop="timeLong" width="100">
        <template slot-scope="scope">
          <div>{{ scope.row.timeLong  }}</div>
          <div
            style="border-top: 1px solid #ddd"
            v-for="(val, index) in scope.row.childrenScore"
            :key="index"
          >
            <div>{{ '\n'+ val.timeLong  }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="等级" align="center" prop="grade" >
        <template slot-scope="scope">
          <div>{{ scope.row.grade  }}</div>
          <div
            style="border-top: 1px solid #ddd"
            v-for="(val, index) in scope.row.childrenScore"
            :key="index"
          >
            <div>{{ '\n'+ val.grade  }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="本次获取的积分" align="center" prop="nowScore" width="120" >
        <template slot-scope="scope">
          <div>{{ scope.row.nowScore  }}</div>
          <div
            style="border-top: 1px solid #ddd"
            v-for="(val, index) in scope.row.childrenScore"
            :key="index"
          >
            <div>{{ '\n'+ val.nowScore  }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="劳动教育累计积分" align="center" prop="allScore" width="120" />
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.labour_score_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="审核部门" align="center" prop="gradeDepartment" />
      <el-table-column label="记录时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.state==2" @click="handleUpdate(scope.row)"
            v-hasPermi="['educationManager:score:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-document" @click="handleDetail(scope.row)">查看</el-button>
          <el-button v-if="scope.row.state == 0" size="mini" type="text" icon="el-icon-edit"
            @click="handleDetail(scope.row, true)" v-hasPermi="['educationManager:score:examine']">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['educationManager:score:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改劳动教育学分对话框 -->
    <el-dialog title="劳动教育积分申报" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <!-- <el-form-item label="学生学号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入学生学号" />
        </el-form-item>
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="班级" prop="classNo">
          <el-input v-model="form.classNo" placeholder="请输入班级" />
        </el-form-item> -->
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="申报类别" prop="ruleId">
              <el-select v-model="form.projectType" placeholder="请选择" value-key="projectId" @change="changeProject"
                clearable style="width: 100%">
                <el-option v-for="option in ruleList" :key="option.projectId" :label="option.projectType"
                  :value="option"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="projectSonDetail" label-width="0">
              <!-- <el-input v-model="form.projectSonDetail" placeholder="请输入子项目内容" /> -->
              <el-select v-model="form.projectSonDetail" placeholder="请选择" @change="changeSonProject" clearable
                style="width: 100%">
                <el-option v-for="option in ruleSonList" :key="option.projectSonDetail" :label="option.projectSonDetail"
                  :value="option"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="审核部门" prop="gradeDepartment">
          <el-select v-if="form.ruleId == 4 || form.ruleId == 7" v-model="form.gradeDepartment" placeholder="请选择"
            clearable style="width: 100%">
            <el-option v-for="(option, index) in selGradeDepartment" :key="index" :label="option"
              :value="option"></el-option>
          </el-select>
          <el-input v-if="form.ruleId != 4 && form.ruleId != 7" v-model="form.gradeDepartment" placeholder="请输入审核部门" />
        </el-form-item>
        <!-- <el-divider content-position="center">劳动交易信息</el-divider> -->
        <el-form-item label="申报项目名称" label-width="100px">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" icon="el-icon-plus" size="mini"
                @click="handleAddLabourScoreProject"></el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="danger" icon="el-icon-delete" size="mini"
                @click="handleDeleteLabourScoreProject"></el-button>
            </el-col>
          </el-row>
          <el-table :data="labourObjNameList" :row-class-name="rowLabourScoreProjectIndex" ref="labourScoreProject"
            style="width:100%">
            <!-- <el-table-column type="selection" width="50" align="center" /> -->
            <el-table-column label="申报项目名称" prop="projectName">
              <template slot-scope="scope">
                <el-input v-model="scope.row.projectName" placeholder="请输入申报项目名称" />
              </template>
            </el-table-column>
            <el-table-column v-if="form.ruleId == 1 || form.ruleId == 2 || form.ruleId == 3"
              :label="'参与时长（' + ((form.ruleId == 1) ? '分钟' : ((form.ruleId == 2) ? '工时' : '小时')) + '）'" prop="timeLong">
              <template slot-scope="scope">
                <el-input type="number" v-model="scope.row.timeLong" placeholder="请输入参与时长" />
                <!-- <el-form-item label="时长" prop="timeLong"> -->
                <!-- <el-date-picker clearable v-model="scope.row.timeLong" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择时长">
                  </el-date-picker> -->
                <!-- </el-form-item> -->
              </template>
            </el-table-column>
            <el-table-column v-if="form.ruleId == 6 && form.projectSonId != 12" label="选择积分" prop="nowScore">
              <template slot-scope="scope">
                <el-select v-model="scope.row.grade" placeholder="请选择积分" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <!-- <el-option label="院级1分" value="1"></el-option>
                  <el-option label="校级2分" value="2"></el-option>
                  <el-option label="市级3分" value="3"></el-option>
                  <el-option label="省级及以上4分" value="4"></el-option> -->
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column v-if="form.ruleId == 7" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                <el-select v-model="scope.row.grade" placeholder="请选择积分" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column v-if="form.ruleId == 8" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                <el-select v-model="scope.row.grade" placeholder="请选择积分" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column v-if="form.ruleId == 4" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                <el-select v-model="scope.row.nowScore" placeholder="请选择积分" value-key="projectId" clearable
                  style="width: 100%">
                  <el-option label="普通服务5分" value="5"></el-option>
                  <el-option label="风采大赛十佳团队提名奖以上10分" value="10"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="参与日期" prop="nowTime">
              <template slot-scope="scope">
                <!-- <el-input v-model="scope.row.nowTime" placeholder="请输入参与日期" /> -->
                <el-date-picker clearable v-model="scope.row.nowTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择参与日期">
                </el-date-picker>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>


        <!-- <el-form-item label="等级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入等级" />
        </el-form-item>
        <el-form-item label="本次积分" prop="nowScore">
          <el-input v-model="form.nowScore" placeholder="请输入本次获取的积分" />
        </el-form-item> -->
        <!-- <el-form-item label="累计积分" prop="allScore">
          <el-input v-model="form.allScore" placeholder="请输入劳动教育累计积分" />
        </el-form-item> -->
        <!-- <el-form-item label="项目名称" prop="gradeDepartment">
          <el-input v-model="form.gradeDepartment" placeholder="请输入申报项目名称" />
        </el-form-item> -->
        <!-- <el-form-item label="佐证材料" prop="gradeDepartment">
          <el-input v-model="form.gradeDepartment" placeholder="请输入审核部门" />
        </el-form-item> -->
        <el-form-item label="佐证材料">
          <span style="color:#999;">证明图片应包括姓名、奖项名称、单位级别、有效印章等关键信息。</span>
          <image-upload v-model="form.data1" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提交审核</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--查看积分详情 -->
    <el-dialog title="查看积分详情" :visible.sync="detailOpen" width="800px" append-to-body>
      <el-form ref="scoreDetail" :model="scoreDetail" :rules="rules" label-width="100px">
        <el-form-item label="项目类型" prop="projectType">
          <span>{{ scoreDetail.projectType }}—{{ scoreDetail.projectSonDetail }}</span>
        </el-form-item>
        <el-form-item label="审核部门" prop="gradeDepartment">
          <span>{{ scoreDetail.gradeDepartment }}</span>
        </el-form-item>
        <el-form-item label="申报项目名称" label-width="100px">
          <el-table :data="labourObjNameList" :row-class-name="rowLabourScoreProjectIndex" ref="labourScoreProject"
            style="width:100%">
            <!-- <el-table-column type="selection" width="50" align="center" /> -->
            <el-table-column label="申报项目名称" prop="projectName">
              <template slot-scope="scope">
                {{ scope.row.projectName }}
              </template>
            </el-table-column>
            <el-table-column v-if="scoreDetail.ruleId == 1 || scoreDetail.ruleId == 2 || scoreDetail.ruleId == 3"
              :label="'参与时长（' + ((scoreDetail.ruleId == 1) ? '分钟' : ((scoreDetail.ruleId == 2) ? '工时' : '小时')) + '）'"
              prop="timeLong">
              <template slot-scope="scope">
                {{ scope.row.timeLong }}
              </template>
            </el-table-column>
            <el-table-column v-if="scoreDetail.ruleId == 6 && scoreDetail.projectSonId != 12" label="选择积分"
              prop="nowScore">
              <template slot-scope="scope">
                {{ scope.row.grade }}-{{ scope.row.nowScore }}分
                <!-- <el-select v-model="scope.row.grade" placeholder="请选择等级" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column v-if="scoreDetail.ruleId == 7" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                {{ scope.row.grade }}-{{ scope.row.nowScore }}分
                <!-- <el-select v-model="scope.row.grade" placeholder="请选择积分" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column v-if="scoreDetail.ruleId == 8" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                {{ scope.row.grade }}-{{ scope.row.nowScore }}分
                <!-- <el-select v-model="scope.row.grade" placeholder="请选择积分" value-key="projectId" clearable
                  @change="(val) => changeScore(val, scope.row.index)" style="width: 100%">
                  <el-option v-for="(option, index) in selGradeScore" :key="index"
                    :label="option.range + '-' + option.score + '分'" :value="option"></el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column v-if="scoreDetail.ruleId == 4" label="选择等级" prop="nowScore">
              <template slot-scope="scope">
                {{ scope.row.grade }}-{{ scope.row.nowScore }}分
                <!-- <el-select v-model="scope.row.nowScore" placeholder="请选择积分" value-key="projectId" clearable
                  style="width: 100%">
                  <el-option label="普通服务5分" value="5"></el-option>
                  <el-option label="风采大赛十佳团队提名奖以上10分" value="10"></el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column label="参与日期" prop="nowTime">
              <template slot-scope="scope">
                <!-- <el-input v-model="scope.row.nowTime" placeholder="请输入参与日期" /> -->
                {{ scope.row.nowTime }}
                <!-- <el-date-picker clearable v-model="scope.row.nowTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择参与日期">
                </el-date-picker> -->
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <!-- <el-form-item label="本次积分" prop="nowScore">
          <span>{{ scoreDetail.nowScore }}</span>
        </el-form-item> -->
        <el-form-item label="佐证材料" prop="data1">
          <image-preview style="margin-right:20px;" v-for="(val, index) in scoreDetail.data1"
            :key="index" :src="val" :width="90" :height="90" />
        </el-form-item>
        <el-form-item v-if="ifExamine && passFlag == 2" label="审核意见" prop="reason">
          <el-input v-model="reason" placeholder="请输入审核意见" />
        </el-form-item>
        <el-form-item v-if="ifExamine" label="审核">
          <el-button size="mini" :type="btnTypeStyle1" @click="pass(1)">通过 </el-button>
          <el-button size="mini" :type="btnTypeStyle2" @click="pass(2)">不通过 </el-button>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormE" v-if="ifExamine">审核提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 审核对话框 -->
    <el-dialog :title="title" :visible.sync="examineOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="审核意见" prop="examineComments1">
          <el-input v-model="examineComments1" placeholder="请输入审核意见" />
        </el-form-item> -->
        <el-button type="primary" @click="submitFormE('0')">审核拒绝</el-button>
        <el-button type="primary" @click="submitFormE('1')">审核通过</el-button>
      </el-form>
      <!--      <div slot="footer" class="dialog-footer">
	        <el-button type="primary" @click="submitForm">确 定</el-button>
	      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { listScore, getProjectlist, getScore, delScore, addScore, updateScore } from "@/api/educationManager/score";
import { listRule } from "@/api/system/rule";
import { GetYearList } from "@/api/teacherStu";
import { getToken } from '@/utils/auth';
import { mapGetters } from 'vuex';


export default {
  name: "Score",
  dicts: ['model_nature', 'score_standard', 'score_type', 'coursr_type', 'scoring_method', 'dept_type', 'labour_score_state'],
  computed: {
    ...mapGetters(['name']),
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 劳动教育学分表格数据
      scoreList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        term: null,
        userName: null,
        studentName: null,
        classNo: null,
        projectType: null,
        projectSonDetail: null,
        timeLong: null,
        grade: null,
        nowScore: null,
        allScore: null,
        gradeDepartment: null,
      },
      // 表单参数
      form: {
        ruleId: null,
        scoreType: null,
      },
      // 表单校验
      rules: {
      },
      // 学期选项
      schoolYears: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/smartScore/export',
      },
      ruleList: [],
      ruleSonList: [],

      checkedLabourScoreProject: [],

      labourObjNameList: [{
        projectName: "",
        timeLong: 0,
        nowTime: "",
        grade: "",
        nowScore: "",
      }],
      // 审核
      examineOpen: false,
      // 查看
      detailOpen: false,
      scoreDetail: {},
      //荣誉称号下拉数据
      selHonorScore: [
        { range: '院级', score: '1' },
        { range: '校级', score: '2' },
        { range: '市级', score: '3' },
        { range: '省级及以上', score: '4' },
      ],
      // 参加竞赛下拉数据
      selMatchScore: [
        { range: '国一', score: '8' },
        { range: '国二', score: '7' },
        { range: '国三', score: '6' },
        { range: '省一', score: '6' },
        { range: '省二', score: '5' },
        { range: '省三', score: '4' },
        { range: '未获奖', score: '2' },
      ],
      //其他活动下拉数据
      selOtherScore: [
        { range: '院级', score: '1' },
        { range: '校级', score: '2' },
      ],
      selGradeDepartment: [],
      selGradeScore: [],
      // 审核
      passFlag: null,
      btnTypeStyle1: 'primary',
      btnTypeStyle2: 'primary',
      // 是否审核操作
      ifExamine: false,
      // 审核意见
      reason: null,
      // 当前学期
      curterm:null,
    };
  },
  created() {
    // GetYearList().then(response => {
    //   console.log(response, 'Years');
    //   this.schoolYears = response.rows;
    // });

    this.getList();
    this.getYear();

  },
  methods: {
    getYear() {
      GetYearList().then(response => {
        console.log(response, 'Years');
        this.schoolYears = response.rows;
        for (let i = 0; i < response.total; i++) {
          if (response.rows[i].defaultValue == '1') {
            this.curterm = response.rows[i].schoolYearId;
          }
        }
      });
    },
    /** 查询劳动教育学分列表 */
    getList() {
      this.loading = true;
      // this.scoreList = [];
      listScore(this.queryParams).then(response => {
        this.scoreList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询赋分规则下拉框 */
    getRuleList() {
      getProjectlist().then(response => {
        this.ruleList = response.data;
      });
    },
    changeProject(item) {
      console.log(item, "item");
      this.form.projectSonDetail = null;
      this.form.gradeDepartment = null;
      this.form.ruleId = item.projectId;
      this.form.projectType = item.projectType;
      this.form.scoreType = item.scoreType;
      this.ruleSonList = item.projectSons;
      console.log(this.form.ruleId, "ruleId");
      this.selGradeScore = item.projectId == 6 ? this.selHonorScore : item.projectId == 7 ? this.selMatchScore : this.selOtherScore;
    },
    changeSonProject(item) {
      this.form.projectSonDetail = item.projectSonDetail;
      this.form.projectSonId = item.id;
      if (this.form.ruleId == 4 || this.form.ruleId == 7) {
        this.selGradeDepartment = item.deptType.split('、')
      } else {
        this.form.gradeDepartment = item.deptType;
      }
    },
    changeScore(item, index) {
      console.log(item, index, "ittt")
      this.labourObjNameList[index - 1].grade = item.range;
      this.labourObjNameList[index - 1].nowScore = item.score;
    },
    // 审核
    pass(type) {
      if (type == 1) {
        this.passFlag = type;
        this.btnTypeStyle1 = 'success';
        this.btnTypeStyle2 = 'primary';
      } else {
        this.passFlag = type;
        this.btnTypeStyle1 = 'primary';
        this.btnTypeStyle2 = 'success';
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.detailOpen = false;
      this.examineOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        scoreId: null,
        userName: null,
        studentName: null,
        classNo: null,
        projectType: null,
        projectSonDetail: null,
        timeLong: null,
        grade: null,
        nowScore: null,
        allScore: null,
        gradeDepartment: null,
        nowTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.scoreId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.labourObjNameList = [];
      this.title = "添加劳动教育学分";
      // this.handleAddLabourScoreProject();
      // this.getYear();
      this.getRuleList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const scoreId = row.scoreId || this.ids
      // getScore(scoreId).then(response => {
      //   this.form = response.data;
      //   this.title = "修改劳动教育学分";
      // });
      this.reason = "";
      this.form = { ...row };
      // this.form.data1 = this.form.data1.split(',');
      this.labourObjNameList = [];
      this.labourObjNameList[0] = {
        projectName: this.form.projectName,
        timeLong: this.form.timeLong,
        nowTime: this.form.nowTime,
        grade: this.form.grade,
        nowScore: this.form.nowScore
      };
      if (this.form.childrenScore.length > 0) {
        console.log(this.labourObjNameList);
        this.labourObjNameList = this.labourObjNameList.concat(this.form.childrenScore);
      }
      console.log(this.labourObjNameList, "labourList");
      this.open = true;
    },
    /** 提交按钮 */
    submitForm() {
      // this.form = { ...this.form, ...this.labourObjNameList[0] };
      console.log(this.form,"this.form");
      this.form.term = this.curterm;
      this.form.userName = this.name;
      this.form.timeLong = parseInt(this.form.timeLong);
      var listForm = [];
      for (let i = 0; i < this.labourObjNameList.length; i++) {
        listForm[i] = { ...this.form, ...this.labourObjNameList[i] };
      }
      console.log(this.form, "forem")
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.scoreId != null) {
            updateScore(listForm).then(response => {
              if (response.code == 200) {
              this.$modal.msgSuccess(response.msg);
              this.open = false;
              this.getList();
              }
            });
          } else {
          addScore(listForm).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess(response.msg);
              this.open = false;
              this.getList();
            }
          });
          }
        }
      });
    },
    // 查看/审核
    handleDetail(row, ifExamine) {
      this.reason = "";
      this.ifExamine = ifExamine;
      this.scoreDetail = { ...row };
      this.scoreDetail.data1 = this.scoreDetail.data1.split(',');
      this.labourObjNameList = [];
      this.labourObjNameList[0] = {
        projectName: this.scoreDetail.projectName,
        timeLong: this.scoreDetail.timeLong,
        nowTime: this.scoreDetail.nowTime,
        grade: this.scoreDetail.grade,
        nowScore: this.scoreDetail.nowScore
      };
      if (this.scoreDetail.childrenScore.length > 0) {
        console.log(this.labourObjNameList);
        this.labourObjNameList = this.labourObjNameList.concat(this.scoreDetail.childrenScore);
      }
      console.log(this.labourObjNameList, "labourList");
      this.detailOpen = true;
    },
    // 审核
    examineOpenF(row) {
      this.title = ' 劳动积分申报审核';
      this.form = row;
      this.examineOpen = true;
    },
    // 审核确认按钮
    submitFormE() {
      if (this.passFlag) {
        let subForm = {};
        subForm.state = this.passFlag;
        subForm.reason = this.reason;
        subForm.scoreId = this.scoreDetail.scoreId;
        subForm.userName = this.scoreDetail.userName;
        updateScore(subForm).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess("审核成功");
            this.examineOpen = false;
            this.detailOpen = false;
            this.getList();
          }
        });
      } else {
        this.$modal.msgError("请选择审核结果!");
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const scoreIds = row.scoreId || this.ids;
      this.$modal.confirm('是否确认删除劳动教育学分编号为"' + scoreIds + '"的数据项？').then(function () {
        return delScore(scoreIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('educationManager/score/export', {
        ...this.queryParams
      }, `score_${new Date().getTime()}.xlsx`)
    },

    handleImport() {
      this.upload.title = '智能数据分析';
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        '/committee/member/importTemplate3',
        {},
        `labour_template_${new Date().getTime()}.xlsx`
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        '</div>',
        '导入结果',
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 劳动交易信息序号 */
    rowLabourScoreProjectIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 劳动交易信息添加按钮操作 */
    handleAddLabourScoreProject() {
      let obj = {};
      obj.projectName = "";
      obj.timeLong = 0;
      obj.nowTime = "";
      obj.grade = "";
      obj.nowScore = "";
      this.labourObjNameList.push(obj);
    },
    /** 劳动交易信息删除按钮操作 */
    handleDeleteLabourScoreProject() {
      this.labourObjNameList.pop();
    },
  }
};
</script>
